<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/4
  Time: 13:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div class="row">
    <!-- NEW WIDGET START -->
    <article class="col-sm-12 col-md-12 col-lg-12">
        <div class="jarviswidget well" id="wid-id-3"
             data-widget-colorbutton="false"
             data-widget-editbutton="false"
             data-widget-togglebutton="false"
             data-widget-deletebutton="false"
             data-widget-fullscreenbutton="false"
             data-widget-custombutton="false"
             data-widget-sortable="false">
            <!-- widget div-->
            <div>
                <div class="widget-body">
                    <a class="btn btn-default" id="linkman-re-common" href="javascript:void(0)">
                        <i class="fa fa-lg fa-mail-reply-all"></i>返回
                    </a>
                    <shiro:hasAnyRoles name="wechat">
                    <a class="btn btn-default pull-right pull-right-fix" id="btn-edit-common" href="javascript:void(0);"><i class="fa fa-lg fa-edit"></i> 编辑</a>
                    </shiro:hasAnyRoles>
                        <hr class="simple">
                    <form id="linkman" class="smart-form" novalidate="novalidate" action="" method="post">
                        <input type="hidden" name="keyId" id="keyId1" value="<s:property value="linkman.id" />"/>
                        <input type="hidden" name="clientId" id="clientId" value="<s:property value="clientId" />"/>
                        <header id="title" style="display: block;">
                            联系人信息
                        </header>
                        <fieldset>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    所属客户
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="cname" id="cname" value="<s:property value="linkman.client.name"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    姓名
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="name" id="name" value="<s:property value="linkman.name"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    常用称呼
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="subName" id="subName" value="<s:property value="linkman.subName"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    职位
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="duty" id="duty" value="<s:property value="linkman.duty"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    办公电话
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="tel" id="tel" value="<s:property value="linkman.tel"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    <i class="fa fa-asterisk txt-color-red"></i>
                                    手机
                                </label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input type="text" name="mobile" id="mobile" value="<s:property value="linkman.mobile"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">备用手机</label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input name="mobile_back" id="mobile_back" type="text" value="<s:property value="linkman.mobile_back"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">邮箱</label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input name="email" id="email" type="text" value="<s:property value="linkman.email"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">
                                    生日</label>
                                <section class="col col-2">
                                    <label class="input state-disabled">
                                        <input name="birthday" id="birthday" type="text" value="<s:date name="linkman.birthday" format="yyyy-MM-dd"></s:date>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">喜好</label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input name="preferences" id="preferences" type="text" value="<s:property value="linkman.preferences"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <div class="row">
                                <label class="label col col-2">备注</label>
                                <section class="col col-5">
                                    <label class="input state-disabled">
                                        <input name="remark" id="remark" type="text" value="<s:property value="linkman.remark"/>" disabled>
                                    </label>
                                </section>
                            </div>
                            <%--<div class="row">--%>
                                <%--<label class="label col col-2">照片</label>--%>
                                <%--<section class="col col-5">--%>
                                    <%--<img id="link_img" style="top:0;margin-bottom:0;width:80px;heigth:80px;" src="file.action?gridId=<s:property value="fileManage.gridId" />" />--%>
                                <%--</section>--%>
                            <%--</div>--%>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </article>
</div>

<script>
    //校验
    $("#linkman").validate({
        rules : {
            name : {
                required : true
            }
        },
        messages : {
            name : {
                required : '请输入联系人名字'
            }
        },
        errorPlacement : function(error, element) {
            error.insertAfter(element.parent());
        }
    });

    $('.hasDatepicker').datetimepicker({
        format: 'yyyy-mm-dd',
        weekStart: 1,
        autoclose: true,
        todayBtn: 'linked',
        language: 'zh-CN',
        minView:2
    });
    //保存
    $("#btn-save-common").click(
            function(e) {
                //var $valid = $("#linkman").valid();
                //if(!$valid) return false;
                $.SmartMessageBox({
                    title : "提示：",
                    content : "确定提交吗？",
                    buttons : '[取消][确认]'
                }, function(ButtonPressed) {
                    if (ButtonPressed === "取消") {
                        e.preventDefault();
                        e.stopPropagation();
                        return;
                    }
                    if (ButtonPressed === "确认") {
                        $("#btn-save-common").attr("disabled", "disabled");
                        form_save("linkman","<%=path%>/com/ajax-linkman!save.action");
                        loadURL("ajax!client.action",$('#content'));
                    }
                });
            }
    );
</script>
<script type="text/javascript">
    //上传文件
    inputLoad({
        objId:"filename",
        entityName:"fileReplyId",
        sourceId:"fileId"
    });

    $(function(){
        var pdata= {
            keyId:$("#keyId1").val(),
            flowName:"linkman"
        };
        multiDuty(pdata);
    });
    $("input[name=isDelegate]").unbind().bind("click",function(e){
        $("#agentName").val("");
        if($(this).prop("checked") && $(this).val() == "1"){
            $("#agentDiv").show();
        }else{
            $("#agentDiv").hide();
        }
    });

</script>

<script type="text/javascript">
    function loadCard(){
        area_save($("#province").val(),$("#city").val(),$("#county").val());
        $("a#areaselect_text").show();
    }
    loadCard();
    loadScript("../resource/com/js/data.js", loadSelect);
    function loadSelect(){
        loadScript("../resource/com/js/areaselect.js", loadLocation);
    }
    function loadLocation(){
        var locObj ;
        $("#areaselect_text").click(function(){
            $("#areaselect_span").show();
            locObj = new locationCard({
                ids: ['province', 'city', 'county']
            });
            locObj.init();
            $("#areaselect_text").hide();
        });
        $("#areaselect_span").hide();
        $("#areaselect_check").click(function(){

            if($("#province").val()!=null){
                area_save($("#province").val(),$("#city").val(),$("#county").val());
                $("#areaselect_span").hide();
                $("#areaselect_text").show();
                locObj.destoryCards();
            }else{
                $.smallBox({
                    title : "操作失败",
                    content : "<i class='fa fa-clock-o'></i> <i> 请选择地区，地区不能为空！</i>",
                    color : "#C46A69",
                    iconSmall : "fa fa-times fa-2x fadeInRight animated",
                    timeout : 6000
                });
                locObj.destoryCards();
            }
        })
        $("#areaselect_cancel").click(function(){

            $("#areaselect_span").hide();
            $("#areaselect_text").show();
            locObj.destoryCards();
        })
    }
    function area_save(p,city,county){
        $("a#areaselect_text").text(p+city+county);
        if(p == "") {
            $("a#areaselect_text").text("请选择地址");
        }
    }

    //返回视图
    $("#linkman-re-common").click(function(){
        loadURL("ajax-linkman!show.action",$('div#business_data'));
    });

    function load_client_jqGrid(){
        jQuery("#ajax_linkman_table").jqGrid({
            url:'ajax-linkman!list.action?clientId='+$('#keyId').val(),
            datatype: "json",
            colNames:['客户名称',"姓名",'常用称呼',"职位","办公电话","手机","邮箱","生日","操作","id"],
            colModel:[
                {name:'cname',index:'cname', width:80,sortable:true},
                {name:'name',index:'name', width:80,sortable:false},
                {name:'subname',index:'subname', width:80},
                {name:'duty',index:'duty', width:120},
                {name:'tel',index:'tel', width:100},
                {name:'mobile',index:'mobile',width:100},
                {name:'email',index:'email',width:100},
                {name:'birthday',index:'birthday',width:100},
                {name:'act',index:'act', width:210,sortable:false,fixed:true},
                {name:'id',index:'id',hidden:true},
            ],
            rowNum : 10,
            rowList:[10,20,30],
            pager : '#ajax_linkman_list_page',
            sortname : 'id',
            sortorder : "asc",
            gridComplete:function(){
                var ids=$("#ajax_linkman_table").jqGrid('getDataIDs');
                for(var i=0;i<ids.length;i++){
                    var cl=ids[i];
                    var rowData = $("#ajax_linkman_table").jqGrid("getRowData",cl);
                    var de="<button class='btn btn-default' data-original-title='查看' onclick=\"fn_linkman_read('"+cl+"');\"><i class='fa fa-eye'></i>查看</button>"+" ";
                    var dt="<button class='btn btn-default' data-original-title='删除' onclick=\"fn_linkman_destroy('"+cl+"');\"><i class='fa fa-eye'></i>删除</button>"+" ";
                    jQuery("#ajax_linkman_table").jqGrid('setRowData',ids[i],{act:de+dt});
                }

                $(".ui-jqgrid-bdiv").css("overflow-x","hidden");

                jqGridStyle();
            },
            jsonReader: {
                root: "dataRows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems : false
            },
            multiselect : false,
            rownumbers:true,
            gridview:true,
            shrinkToFit:true,
            viewrecords: true,
            autowidth: true,
            height:'auto',
            forceFit:true,
            loadComplete: function() {
            }
        });
        $(window).on('resize.jqGrid', function() {
            jQuery("#ajax_linkman_table").jqGrid('setGridWidth', $("#ajax_linkman_list_row").width());
        });

        jQuery("#ajax_linkman_table").jqGrid('navGrid', "#ajax_linkman_list_page", {
            edit : false,
            add : false,
            del : false,
            search:false
        });
    }

    //编辑
    $("a[id=btn-edit-common]").click(function(){
        loadURL("ajax-linkman!input.action?keyId="+$("#keyId1").val(),$('div#business_data'));
    });
</script>